# 循环链接 + 方式生成
def test1():
    l = []
    for i in range(1000):
        l = l + [i]


# append
def test2():
    l = []
    for i in range(1000):
        l.append(i)


# 列表推导式
def test3():
    l = [i for i in range(1000)]


# range 函数转为列表
def test4():
    l = list(range(1000))


from timeit import Timer

t1 = Timer("test1()", "from __main__ import test1")
t2 = Timer("test2()", "from __main__ import test2")
t3 = Timer("test3()", "from __main__ import test3")
t4 = Timer("test4()", "from __main__ import test4")
print('concat 时间',t1.timeit(number=1000))
print('append 时间',t2.timeit(number=1000))
print('列表推导式 时间',t3.timeit(number=1000))
print('range 时间',t4.timeit(number=1000))
